<?php  
require '../action/functions.php';

session_start();

$hasError = isset($_SESSION['has_error']) ? $_SESSION['has_error'] : false;
$inputBag = isset($_SESSION['input_bag']) ? $_SESSION['input_bag'] : ['username' => ''];
$errorBag = isset($_SESSION['error_bag']) ? $_SESSION['error_bag'] : ['username' => '', 'password' => '', 'pwd_again' => '','code'=>''];

// 销毁session中的错误数据包 （错误数据包是一次性的）
if (isset($_SESSION['has_error'])&&isset($_SESSION['input_bag'])&&isset($_SESSION['error_bag'])) {
	unset($_SESSION['has_error']);
	unset($_SESSION['input_bag']);
	unset($_SESSION['error_bag']);
}

?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>留言板-注册</title>
  <link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
  <div>
  	<form method="post" action="../action/register_action.php">
  	  <div class="row">
  	  	<div class="input">
  	  	  <label for="username">用户名</label>
  	  	  <input type="text" name="username" placeholder="请输入用户名" value="<?=$inputBag['username']?>">
  	  	</div>
  	  	<div class="error">
  	  	  <?php if($hasError) echo $errorBag['username'] ?>
  	  	</div>
  	  	<div class="input">
  	  	  <label for="password">密码</label>
  	  	  <input type="password" name="password" placeholder="请输入密码">
  	  	</div>
  	  	<div class="error">
  	  	  <?php if($hasError) echo $errorBag['password'] ?>
  	  	</div>
  	  	<div class="input">
  	  	  <label for="pwd_again">确认密码</label>
  	  	  <input type="password" name="pwd_again" placeholder="请确认密码"s>
  	  	</div>
        <div class="error">
          <?php if($hasError) echo $errorBag['pwd_again'] ?>
        </div>
        <div class="input">
          <label>验证码</label>
          <input class="code" type="text" name="code" width="100" placeholder="请输入验证码">
        </div>
        <div class="error">
          <?php if ($hasError) echo $errorBag['code'] ?>
        </div>
        <div class="code">
          <a href="register.php"><img src="img/picture.php" align="center"></a>
        </div>
  	  	<div>
  	  	  <input class="button" type="submit" name="register" value="注册">
  	  	</div>
  	  	<div>已有账号？现在<a href="signin.php">登陆</a></div>
  	  </div>
  	</form>
  </div>
</body>
</html>